package com.douqu.game.battle.controller.sprite;


import com.douqu.game.core.config.battle.AIConfig;
import com.douqu.game.core.config.battle.MonsterConfig;
import com.douqu.game.core.config.challenge.BattleInitConfig;
import com.douqu.game.core.config.common.CommonData;
import com.douqu.game.core.config.map.CityArmyConfig;
import com.douqu.game.core.config.map.CityArmyGroupConfig;
import com.douqu.game.core.config.sprite.MasterConfig;
import com.douqu.game.core.e.E_BattleDetailType;
import com.douqu.game.core.entity.battle.BattleInitParam;
import com.douqu.game.core.factory.ConstantFactory;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.util.CoreUtils;

/**
 * Created by bean on 2017/9/13.
 */
public class MonsterController extends SpriteController
{
    private MonsterConfig monsterConfig;

    private int[] monsterLv;
    /**
     * 表示整套卡组都要附加这些属性
     */
    private CommonData[] extAttr;
    /**
     * 主将
     */
    private MasterConfig masterConfig;

    /**
     * 战斗名字 显示
     */
    private String masterName;

    private int masterLv;

    /**
     * 关卡的时候是 关卡ID
     * 官阶的时候是 官阶;位置
     */
    private String indexInfo;

    /**
     *
     */
    private BattleInitConfig battleInitConfig;

    /**
     * 主将AI
     */
    private AIConfig aiConfig;




    public MonsterController(E_BattleDetailType battleDetailType, String data, int serverId, BattleInitParam battleInitParam)
    {
        this.indexInfo = data;
        setServerId(serverId);

        DataFactory dataFactory = DataFactory.getInstance();
        int key = 0, configId = 0;
        if(E_BattleDetailType.PVE_INSTANCE == battleDetailType)
        {
            key = DataFactory.LEVEL_KEY;
            String[] values = data.split(ConstantFactory.UNDERLINE);
            configId = Integer.parseInt(values[0]);
        }
        else if(E_BattleDetailType.PVE_OFFICIAL_RANK == battleDetailType)
        {
            key = DataFactory.OFFICIAL_RANK_KEY;
            String[] strs = data.split(ConstantFactory.UNDERLINE);
            configId = Integer.parseInt(strs[0]);
            this.masterName = strs[2];
        }
        else if(E_BattleDetailType.PVE_HERO_TEMPLE == battleDetailType)
        {
            key = DataFactory.HERO_TEMPLE_KEY;
            configId = Integer.parseInt(data);
        }
        else if(E_BattleDetailType.PVE_EXPEDITION == battleDetailType)
        {
            key = DataFactory.EXPEDITION_KEY;
            configId = Integer.parseInt(data);
        }
        else if(E_BattleDetailType.PVE_SPAN_CAMP == battleDetailType)
        {
            key = DataFactory.CAMP_ROBOT_KEY;
            configId = Integer.parseInt(data);
        }
        else if(E_BattleDetailType.PVE_WORLD_BOSS == battleDetailType)
        {
            key = DataFactory.WORLD_BOSS_KEY;
            configId = Integer.parseInt(data);
        }

        if(configId != 0)
        {
            battleInitConfig = DataFactory.getInstance().getGameObject(key, configId);
            this.masterConfig = dataFactory.getGameObject(DataFactory.MASTER_KEY, battleInitConfig.master);
            this.masterLv = battleInitConfig.masterLv;
            this.monsterConfig = dataFactory.getGameObject(DataFactory.MONSTER_KEY, battleInitConfig.monsterId);
            if(monsterConfig.isNullCardParam())
                this.monsterLv = battleInitConfig.monsterLv;
            this.aiConfig = dataFactory.getGameObject(DataFactory.AI_KEY, battleInitConfig.masterAi);
            if(CoreUtils.isNullOrEmpty(this.masterName))
                this.masterName = battleInitConfig.masterName;
        }
        else
        {
            if(E_BattleDetailType.PVE_WORLD_MAP == battleDetailType
                    || E_BattleDetailType.DATA_WORLD_MAP_PVE == battleDetailType
                    || E_BattleDetailType.DATA_WORLD_MAP_EVE == battleDetailType
                    || E_BattleDetailType.DATA_WORLD_MAP_PVG == battleDetailType
                    || E_BattleDetailType.DATA_WORLD_MAP_EVG == battleDetailType)
            {
                String[] values = data.split(ConstantFactory.UNDERLINE);
                CityArmyConfig cityArmyConfig = DataFactory.getInstance().getGameObject(DataFactory.CITY_ARMY_KEY, Integer.parseInt(values[0]));
                this.masterConfig = dataFactory.getGameObject(DataFactory.MASTER_KEY, cityArmyConfig.master);
                this.masterName = cityArmyConfig.name;
                this.monsterConfig = dataFactory.getGameObject(DataFactory.MONSTER_KEY, cityArmyConfig.monsterId);
                CityArmyGroupConfig cityArmyGroupConfig = DataFactory.getInstance().getGameObject(DataFactory.CITY_ARMY_GROUP_KEY, Integer.parseInt(values[1]));
                this.monsterLv = cityArmyGroupConfig.monsterLv;
                this.masterLv = cityArmyGroupConfig.getLv();
                this.extAttr = cityArmyGroupConfig.paraments;
            }
        }
    }


    public CommonData[] getExtAttr() {
        return extAttr;
    }

    public AIConfig getAiConfig() {
        return aiConfig;
    }

    public MonsterConfig getMonsterConfig() {
        return monsterConfig;
    }

    public int[] getMonsterLv() {
        return monsterLv;
    }

    public MasterConfig getMasterConfig() {
        return masterConfig;
    }

    public int getMasterLv() {
        return masterLv;
    }

    public void setMasterLv(int masterLv) {
        this.masterLv = masterLv;
    }

    @Override
    public String getObjectIndex()
    {
        return indexInfo;
    }

    @Override
    public String getName()
    {
        return masterName;
    }

    public BattleInitConfig getBattleInitConfig() {
        return battleInitConfig;
    }


}
